package com.yaozheng.vocationaltraining.activity;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import org.androidannotations.annotations.ViewById;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.utils.Constants;

import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 修改数据界面
 *
 * @author Administrator
 */
@EActivity(R.layout.activity_update_data)
public class UpdateDataActivity extends BaseActivity {
    @ViewById
    ImageView headRightImage;
    @ViewById
    TextView headTitleText, headRightText;
    @Extra
    String title;
    @Extra
    String value;
    @ViewById
    EditText updateDataContentEdit;

    @AfterViews
    public void initView() {
        headRightImage.setImageResource(R.drawable.save_button_image_ioc);
        if (value != null && !"".equals(value)) {
            updateDataContentEdit.setText(value);
            try {
                updateDataContentEdit.setSelection(value.length());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        headTitleText.setText(title);
//        headRightText.setVisibility(View.VISIBLE);
//        headRightText.setText("确定");
        headRightImage.setVisibility(View.GONE);
    }

    /**
     * 保存点击
     */
    @Click(R.id.headRightImage)
    public void headRightClick() {
        String updateDataContentEditValue = updateDataContentEdit.getText()
                .toString();
        if (!"".equals(updateDataContentEditValue) && value != null && !value.equals(updateDataContentEditValue)) {
            setIntentString("newValue", updateDataContentEditValue);
            setResult(Constants.UPDATE_USER_INFO_RESULT_CODE, getIntent());
        }
        finish();
    }

    @Override
    public void onBackPressed() {
        headRightClick();
    }

}
